﻿using System;
using System.Linq;
using System.Windows.Forms;

namespace NNTH
{
    public partial class fBangDiemHV : DevExpress.XtraEditors.XtraForm
    {
        public fBangDiemHV()
        {
            InitializeComponent();
        }

        Data.QLTTNNTHEntities db = new Data.QLTTNNTHEntities();

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (bangDiemBindingSource.Current != null)
            {

                var report = new Reports.reDiemTheoHV();
                BindingSource bs = (BindingSource)report.DataSource;
                bs.DataSource = this.bangDiemBindingSource.List;
                report.ShowPreviewDialog();

            }
        }

        private void fBangDiemHV_Load(object sender, EventArgs e)
        {
            lopHocBindingSource.DataSource = db.LopHoc;
        }

        private void searchLookUpEdit1_EditValueChanged(object sender, EventArgs e)
        {
            if (searchLookUpEdit1.EditValue != null)
            {
                var lop = searchLookUpEdit1.EditValue.ToString();
                hocVienBindingSource.DataSource = db.HocVien.Where(p => p.MaLop == lop);
            }
        }

        private void hocVienBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            if (hocVienBindingSource.Current != null)
            {
                var HV = ((Data.HocVien)hocVienBindingSource.Current).MaHV;
                bangDiemBindingSource.DataSource = db.BangDiem.Where(p => p.MaHV == HV);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Test");
                bangDiemBindingSource.DataSource = typeof(Data.BangDiem);
            }
        }
    }
}